package de.hwrberlin.remo.diagram.properties;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.forms.widgets.Section;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;

import de.hwrberlin.remo.model.LinkObject;
import de.hwrberlin.remo.model.RemoModelPackage;
import de.hwrberlin.remo.model.RemoObject;

public class HeadSection extends AbstractRemoPropertySection {

	private Section section;

	@Override
	public void createControls(Composite parent,
			TabbedPropertySheetPage aTabbedPropertySheetPage) {
		
		super.createControls(parent, aTabbedPropertySheetPage);
		
		section = getWidgetFactory().createSection(parent, 
				Section.CLIENT_INDENT | Section.TITLE_BAR);
		section.setLayout(new FormLayout());
	}
	
	@Override
	public void refresh() {
		String title    = "";
		EObject eObject = getEObject();
	
		if(eObject != null && eObject instanceof RemoObject) {
			RemoObject exObject = (RemoObject) eObject;
			
			title += getClassLabel(exObject.eClass()) + " ";
			
			if(exObject.getName() != null) {
				title += exObject.getName();
			}
		} 
		
		if(eObject != null && eObject instanceof LinkObject) {
			LinkObject exObject = (LinkObject) eObject;
			
			title += getClassLabel(exObject.eClass()) + " ";
			
			if(exObject.getLinkname() != null) {
				title += exObject.getLinkname();
			}
		} 
		
		section.setText(title);
	}
	
	private String getClassLabel(EClass eClass) {
		if(eClass.equals(RemoModelPackage.eINSTANCE.getAndRule())) {
			return "And Rule";
		
		} else if(eClass.equals(RemoModelPackage.eINSTANCE.getOrRule())) {
			return "Or Rule";
		
		} else if(eClass.equals(RemoModelPackage.eINSTANCE.getKnowledgeBase())) {
			return "Knowledge Base";
		
		} else if(eClass.equals(RemoModelPackage.eINSTANCE.getBooleanFact())) {
			return "Fact";
		
		} else if(eClass.equals(RemoModelPackage.eINSTANCE.getLinksFromFacts())) {
			return "Premise";
			
		} else if(eClass.equals(RemoModelPackage.eINSTANCE.getLinksFromRules())) {
			return "Premise";
		}
		
		return eClass.getName();
	}
}